package com.mall.util;

import org.apache.commons.mail.HtmlEmail;

/**
 * java邮箱发送，qq邮箱发送
 */
public class EmailUtils {

    private static final String USERNAME = "1923836223@qq.com";
    private static final String PASSWORD = "joilnjnicgdjejjg";


    public static boolean sendEmail(String []emails,String msg,String title){
        try {

            HtmlEmail email = new HtmlEmail();
            //基本设置
            email.setSSL(true);
            email.setDebug(true);//
            //设置主邮箱为qq邮箱
            email.setHostName("SMTP.qq.com");
            email.setSmtpPort(587);

            //设置发送的邮箱 PASSWORD不是QQ邮箱密码
            email.setAuthentication(USERNAME,PASSWORD);
            email.setFrom(USERNAME);

            email.addTo(emails);
            email.setMsg(msg);
            email.setSubject(title);

            //执行发送
            email.send();

            return true;


        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

    public static void main(String[] args) {

        String emails[] = {"2945862146@qq.com"};
        String msg = "恭喜你中奖500万元，请及时领取";
        String title = "中奖信息";
        boolean b = sendEmail(emails,msg,title);
        System.out.println("邮件发送"+(b?"成功":"失败"));
    }
}
